<!doctype html>
<html lang="en" data-color-mode="dark">
<head>
<meta charset="utf-8">
<title>package.json 备忘清单
 &#x26;  package.json cheatsheet &#x26;  Quick Reference</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta description="这个快速参考备忘清单，显示了关于 package.json 文件中所需内容的全部内容。

重要字段，为开发人员分享快速参考备忘单。">
<meta keywords="package.json,reference,Quick,Reference,cheatsheet,cheat,sheet">
<link rel="icon" href="data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20height%3D%221em%22%20width%3D%221em%22%3E%20%3Cpath%20d%3D%22m21.66%2010.44-.98%204.18c-.84%203.61-2.5%205.07-5.62%204.77-.5-.04-1.04-.13-1.62-.27l-1.68-.4c-4.17-.99-5.46-3.05-4.48-7.23l.98-4.19c.2-.85.44-1.59.74-2.2%201.17-2.42%203.16-3.07%206.5-2.28l1.67.39c4.19.98%205.47%203.05%204.49%207.23Z%22%20fill%3D%22%23c9d1d9%22%2F%3E%20%3Cpath%20d%3D%22M15.06%2019.39c-.62.42-1.4.77-2.35%201.08l-1.58.52c-3.97%201.28-6.06.21-7.35-3.76L2.5%2013.28c-1.28-3.97-.22-6.07%203.75-7.35l1.58-.52c.41-.13.8-.24%201.17-.31-.3.61-.54%201.35-.74%202.2l-.98%204.19c-.98%204.18.31%206.24%204.48%207.23l1.68.4c.58.14%201.12.23%201.62.27Zm2.43-8.88c-.06%200-.12-.01-.19-.02l-4.85-1.23a.75.75%200%200%201%20.37-1.45l4.85%201.23a.748.748%200%200%201-.18%201.47Z%22%20fill%3D%22%23228e6c%22%20%2F%3E%20%3Cpath%20d%3D%22M14.56%2013.89c-.06%200-.12-.01-.19-.02l-2.91-.74a.75.75%200%200%201%20.37-1.45l2.91.74c.4.1.64.51.54.91-.08.34-.38.56-.72.56Z%22%20fill%3D%22%23228e6c%22%20%2F%3E%20%3C%2Fsvg%3E" type="image/svg+xml">
<link rel="stylesheet" href="../style/style.css">
<link rel="stylesheet" href="../style/katex.css">
</head>
<body><nav class="header-nav"><div class="max-container"><a href="../index.html" class="logo"><svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" height="1em" width="1em">
  <path d="m21.66 10.44-.98 4.18c-.84 3.61-2.5 5.07-5.62 4.77-.5-.04-1.04-.13-1.62-.27l-1.68-.4c-4.17-.99-5.46-3.05-4.48-7.23l.98-4.19c.2-.85.44-1.59.74-2.2 1.17-2.42 3.16-3.07 6.5-2.28l1.67.39c4.19.98 5.47 3.05 4.49 7.23Z" fill="#c9d1d9"></path>
  <path d="M15.06 19.39c-.62.42-1.4.77-2.35 1.08l-1.58.52c-3.97 1.28-6.06.21-7.35-3.76L2.5 13.28c-1.28-3.97-.22-6.07 3.75-7.35l1.58-.52c.41-.13.8-.24 1.17-.31-.3.61-.54 1.35-.74 2.2l-.98 4.19c-.98 4.18.31 6.24 4.48 7.23l1.68.4c.58.14 1.12.23 1.62.27Zm2.43-8.88c-.06 0-.12-.01-.19-.02l-4.85-1.23a.75.75 0 0 1 .37-1.45l4.85 1.23a.748.748 0 0 1-.18 1.47Z" fill="#228e6c"></path>
  <path d="M14.56 13.89c-.06 0-.12-.01-.19-.02l-2.91-.74a.75.75 0 0 1 .37-1.45l2.91.74c.4.1.64.51.54.91-.08.34-.38.56-.72.56Z" fill="#228e6c"></path>
</svg>
<span class="title">Quick Reference</span></a><div class="menu"><a href="javascript:void(0);" class="searchbtn" id="searchbtn"><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 18 18">
  <path fill="currentColor" d="M17.71,16.29 L14.31,12.9 C15.4069846,11.5024547 16.0022094,9.77665502 16,8 C16,3.581722 12.418278,0 8,0 C3.581722,0 0,3.581722 0,8 C0,12.418278 3.581722,16 8,16 C9.77665502,16.0022094 11.5024547,15.4069846 12.9,14.31 L16.29,17.71 C16.4777666,17.8993127 16.7333625,18.0057983 17,18.0057983 C17.2666375,18.0057983 17.5222334,17.8993127 17.71,17.71 C17.8993127,17.5222334 18.0057983,17.2666375 18.0057983,17 C18.0057983,16.7333625 17.8993127,16.4777666 17.71,16.29 Z M2,8 C2,4.6862915 4.6862915,2 8,2 C11.3137085,2 14,4.6862915 14,8 C14,11.3137085 11.3137085,14 8,14 C4.6862915,14 2,11.3137085 2,8 Z"></path>
</svg><span>搜索</span><span>⌘K</span></a><a href="https://github.com/jaywcjlove/reference/blob/main/docs/package.json.md" class="" target="__blank"><svg viewBox="0 0 36 36" fill="currentColor" height="1em" width="1em"><path d="m33 6.4-3.7-3.7a1.71 1.71 0 0 0-2.36 0L23.65 6H6a2 2 0 0 0-2 2v22a2 2 0 0 0 2 2h22a2 2 0 0 0 2-2V11.76l3-3a1.67 1.67 0 0 0 0-2.36ZM18.83 20.13l-4.19.93 1-4.15 9.55-9.57 3.23 3.23ZM29.5 9.43 26.27 6.2l1.85-1.85 3.23 3.23Z"></path><path fill="none" d="M0 0h36v36H0z"></path></svg><span>编辑</span></a><button id="darkMode" type="button"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="light" height="1em" width="1em">
  <path d="M6.995 12c0 2.761 2.246 5.007 5.007 5.007s5.007-2.246 5.007-5.007-2.246-5.007-5.007-5.007S6.995 9.239 6.995 12zM11 19h2v3h-2zm0-17h2v3h-2zm-9 9h3v2H2zm17 0h3v2h-3zM5.637 19.778l-1.414-1.414 2.121-2.121 1.414 1.414zM16.242 6.344l2.122-2.122 1.414 1.414-2.122 2.122zM6.344 7.759 4.223 5.637l1.415-1.414 2.12 2.122zm13.434 10.605-1.414 1.414-2.122-2.122 1.414-1.414z"></path>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" class="dark" height="1em" width="1em">
  <path d="M12 11.807A9.002 9.002 0 0 1 10.049 2a9.942 9.942 0 0 0-5.12 2.735c-3.905 3.905-3.905 10.237 0 14.142 3.906 3.906 10.237 3.905 14.143 0a9.946 9.946 0 0 0 2.735-5.119A9.003 9.003 0 0 1 12 11.807z"></path>
</svg>
</button><script src="../js/dark.js"></script><a href="https://github.com/jaywcjlove/reference" class="" target="__blank"><svg viewBox="0 0 16 16" fill="currentColor" height="1em" width="1em"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg></a></div></div></nav><div class="wrap h1body-exist max-container"><header class="wrap-header h1wrap"><h1 id="packagejson-备忘清单"><svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="1em" width="1em">
  <path d="M107.946667 838.4l57.173333 23.893333v-385.28l-103.68 250.026667c-17.493333 43.52 3.413333 93.44 46.506667 111.36z m832-157.866667L728.32 169.813333a85.888 85.888 0 0 0-77.226667-52.48c-11.093333 0-22.613333 1.706667-33.706666 6.4L302.933333 253.866667a85.290667 85.290667 0 0 0-46.08 110.933333l211.626667 510.72a85.248 85.248 0 0 0 110.933333 46.08l314.026667-130.133333a85.077333 85.077333 0 0 0 46.506667-110.933334zM336.213333 373.333333c-23.466667 0-42.666667-19.2-42.666666-42.666666s19.2-42.666667 42.666666-42.666667 42.666667 19.2 42.666667 42.666667-19.2 42.666667-42.666667 42.666666z m-85.333333 469.333334c0 46.933333 38.4 85.333333 85.333333 85.333333h61.866667l-147.2-355.84v270.506667z"></path>
</svg><a aria-hidden="true" tabindex="-1" href="#packagejson-备忘清单"><span class="icon icon-link"></span></a>package.json 备忘清单</h1><div class="wrap-body">
<p>这个快速参考备忘清单，显示了关于 package.json 文件中所需内容的全部内容。</p>
</div></header><div class="menu-tocs"><div class="menu-btn"><svg aria-hidden="true" fill="currentColor" height="1em" width="1em" viewBox="0 0 16 16" version="1.1" data-view-component="true">
  <path fill-rule="evenodd" d="M2 4a1 1 0 100-2 1 1 0 000 2zm3.75-1.5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zM3 8a1 1 0 11-2 0 1 1 0 012 0zm-1 6a1 1 0 100-2 1 1 0 000 2z"></path>
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#重要字段">重要字段</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#介绍">介绍</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#name">name</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#规则">规则</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#version">version</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#tips">Tips</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#安装-name-包">安装 name 包</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#信息类字段">信息类字段</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#description">description</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#license">license</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#license字段必须是以下之一">license字段必须是以下之一</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#keywords">keywords</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#链接类字段">链接类字段</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#homepage">homepage</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#repository">repository</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#bugs">bugs</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#项目维护类字段">项目维护类字段</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#author">author</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#contributors">contributors</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#文件类信息">文件类信息</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#files">files</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#main">main</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#man">man</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#directories">directories</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#bin">bin</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#types">types</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#打包包字段">打包包字段</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#esnext">esnext</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#module">module</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#browser">browser</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#exports-导出">exports 导出</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#exports-导出子路径中的模块">exports 导出子路径中的模块</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#exports-简写--唯一的导出">exports 简写 (. 唯一的导出)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#条件导出exports">条件导出(exports)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#main-vs-exports">main Vs exports</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#任务类字段">任务类字段</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#scripts">scripts</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#特定的-scripts">特定的 scripts</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#config">config</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#依赖描述类字段">依赖描述类字段</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#dependencies">dependencies</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#workspaces">workspaces</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#devdependencies">devDependencies</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#overrides">overrides</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#peerdependencies">peerDependencies</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#optionaldependencies">optionalDependencies</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#bundleddependencies">bundledDependencies</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#peerdependenciesmeta">peerDependenciesMeta</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#系统">系统</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#engines">engines</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#os">os</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#cpu">cpu</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#发布">发布</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#private">private</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#publishconfig">publishConfig</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#yarn">Yarn</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#flat">flat</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#resolutions">resolutions</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#另见">另见</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="重要字段"><a aria-hidden="true" tabindex="-1" href="#重要字段"><span class="icon icon-link"></span></a>重要字段</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="介绍"><a aria-hidden="true" tabindex="-1" href="#介绍"><span class="icon icon-link"></span></a>介绍</h3><div class="wrap-body">
<p>本快速参考备忘清单是您需要了解的关于 package.json 文件中所需内容的全部内容。 它必须是实际的 JSON，而不仅仅是 JavaScript 对象字面量。</p>
<ul>
<li><a href="https://docs.npmjs.com/files/package.json">npm 文档</a> <em>(npmjs.com)</em></li>
<li><a href="https://classic.yarnpkg.com/en/docs/package-json">yarnpkg 文档</a> <em>(yarnpkg.com)</em></li>
<li><a href="https://nodejs.org/api/packages.html">packages 文档</a> <em>(nodejs.org)</em></li>
<li><a href="./npm.html">npm 备忘清单(速查表)</a> <em>(jaywcjlove.github.io)</em></li>
</ul>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="name"><a aria-hidden="true" tabindex="-1" href="#name"><span class="icon icon-link"></span></a><code>name</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"my-awesome-package"</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<h4 id="规则"><a aria-hidden="true" tabindex="-1" href="#规则"><span class="icon icon-link"></span></a>规则</h4>
<ul>
<li>必须小于或等于214个字符(包括 <code>@scope/</code> 范围包)</li>
<li>不能以点（<code>.</code>）或下划线（<code>_</code>）开头</li>
<li>名称中不得包含大写字母</li>
<li>必须仅使用URL安全字符</li>
</ul>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="version"><a aria-hidden="true" tabindex="-1" href="#version"><span class="icon icon-link"></span></a><code>version</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"version"</span><span class="token operator">:</span> <span class="token string">"1.0.0"</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>包的当前版本，严格遵循 <a href="http://semver.org/lang/zh-CN/">Semantic Versioning 2.0.0</a> 语义化版本规范。</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="tips"><a aria-hidden="true" tabindex="-1" href="#tips"><span class="icon icon-link"></span></a>Tips</h3><div class="wrap-body">
<ul>
<li>不要使用和 <code>Node.js</code> 核心模块相同的名字。</li>
<li>不要在名字里包含 <code>js</code> 或者 <code>node</code> 单词。</li>
<li>短小精悍，让人看到名字就大概了解包的功能，记住它也会被用在 <code>require()</code> 调用里。</li>
<li>保证名字在 <a href="https://www.npmjs.com/">npm registry</a> 里是唯一的。</li>
<li>name 和 version 字段一起用于创建唯一ID</li>
</ul>
<p>如果没有 <code>name</code> 和<code>version</code> 字段，您的包将无法安装</p>
</div></div></div><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="安装-name-包"><a aria-hidden="true" tabindex="-1" href="#安装-name-包"><span class="icon icon-link"></span></a>安装 <code>name</code> 包</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->
<pre class="language-sh"><code class="language-sh code-highlight"><span class="code-line"><span class="token function">yarn</span> <span class="token function">add</span> <span class="token punctuation">[</span>包名<span class="token punctuation">]</span>
</span><span class="code-line"><span class="token comment"># or</span>
</span><span class="code-line"><span class="token function">npm</span> <span class="token function">install</span> <span class="token punctuation">[</span>包名<span class="token punctuation">]</span>
</span></code></pre>
<p>安装后存放位置</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">node_modules/<span class="token punctuation">[</span>包名<span class="token punctuation">]</span>
</span></code></pre>
<p>npmjs 下载地址</p>
<pre class="wrap-text"><code class="language-bash code-highlight"><span class="code-line">https://registry.npmjs.org/<span class="token punctuation">[</span>包名<span class="token punctuation">]</span>/-/<span class="token punctuation">[</span>包名<span class="token punctuation">]</span>-<span class="token punctuation">[</span>version<span class="token punctuation">]</span>.tgz
</span></code></pre>
<!--rehype:className=wrap-text-->
<p>这是您的 <code>包</code> 的名称。 它在URL中使用，作为参数命令行，以及 <code>node_modules</code> 中的目录名。</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="信息类字段"><a aria-hidden="true" tabindex="-1" href="#信息类字段"><span class="icon icon-link"></span></a>信息类字段</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="description"><a aria-hidden="true" tabindex="-1" href="#description"><span class="icon icon-link"></span></a><code>description</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"description"</span><span class="token operator">:</span> <span class="token string">"我的包的概要简短描述"</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>帮助使用者了解包的功能的字符串，包管理器也会把这个字符串作为搜索关键词。</p>
</div></div></div><div class="wrap h3body-exist col-span-2 row-span-2"><div class="wrap-header h3wrap"><h3 id="license"><a aria-hidden="true" tabindex="-1" href="#license"><span class="icon icon-link"></span></a><code>license</code></h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2 row-span-2-->
<p>所有包都应该指定许可证，以便让用户了解他们是在什么授权下使用此包，以及此包还有哪些附加限制。</p>
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"license"</span><span class="token operator">:</span> <span class="token string">"MIT"</span><span class="token punctuation">,</span>
</span><span class="code-line">  <span class="token property">"license"</span><span class="token operator">:</span> <span class="token string">"(MIT or GPL-3.0)"</span><span class="token punctuation">,</span>
</span><span class="code-line">  <span class="token property">"license"</span><span class="token operator">:</span> <span class="token string">"SEE LICENSE IN LICENSE_FILENAME.txt"</span><span class="token punctuation">,</span>
</span><span class="code-line">  <span class="token property">"license"</span><span class="token operator">:</span> <span class="token string">"UNLICENSED"</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>鼓励使用开源 <a href="https://opensource.org/licenses/alphabetical">(OSI-approved)</a> 许可证，除非你有特别的原因不用它。 如果你开发的包是你工作的一部分，最好和公司讨论后再做决定。</p>
<h4 id="license字段必须是以下之一"><a aria-hidden="true" tabindex="-1" href="#license字段必须是以下之一"><span class="icon icon-link"></span></a><strong>license字段必须是以下之一</strong></h4>
<ul>
<li>如果你使用标准的许可证，需要一个有效地 <a href="https://spdx.org/licenses/">SPDX 许可证标识</a>。</li>
<li>如果你用多种标准许可证，需要有效的 <a href="https://www.npmjs.com/package/spdx">SPDX 许可证表达式2.0语法表达式</a>。</li>
<li>如果你使用非标准的许可证，一个 <code>SEE LICENSE IN &#x3C;文件名></code> 字符串指向你的包里顶级目录的一个 &#x3C;文件名>。</li>
<li>如果你不想在任何条款下授权其他人使用你的私有或未公开的包，一个 <code>UNLICENSED</code> 字符串。</li>
</ul>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="keywords"><a aria-hidden="true" tabindex="-1" href="#keywords"><span class="icon icon-link"></span></a><code>keywords</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"keywords"</span><span class="token operator">:</span> <span class="token punctuation">[</span>
</span><span class="code-line">    <span class="token string">"short"</span><span class="token punctuation">,</span> <span class="token string">"relevant"</span><span class="token punctuation">,</span> <span class="token string">"keywords"</span>
</span><span class="code-line">  <span class="token punctuation">]</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>一个字符串数组，当在包管理器里搜索包时很有用。</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="链接类字段"><a aria-hidden="true" tabindex="-1" href="#链接类字段"><span class="icon icon-link"></span></a>链接类字段</h2><div class="wrap-body">
<p>各种指向项目文档、issues 上报，以及代码托管网站的链接字段。</p>
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="homepage"><a aria-hidden="true" tabindex="-1" href="#homepage"><span class="icon icon-link"></span></a><code>homepage</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"homepage"</span><span class="token operator">:</span> <span class="token string">"https://your-package.org"</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>是包的项目主页或者文档首页。</p>
</div></div></div><div class="wrap h3body-not-exist col-span-2 row-span-2"><div class="wrap-header h3wrap"><h3 id="repository"><a aria-hidden="true" tabindex="-1" href="#repository"><span class="icon icon-link"></span></a><code>repository</code></h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2 row-span-2-->
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"repository"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"type"</span><span class="token operator">:</span> <span class="token string">"git"</span><span class="token punctuation">,</span> <span class="token property">"url"</span><span class="token operator">:</span> <span class="token string">"https://github.com/user/repo.git"</span>
</span><span class="code-line">  <span class="token punctuation">}</span><span class="token punctuation">,</span>
</span><span class="code-line">  <span class="token property">"repository"</span><span class="token operator">:</span> <span class="token string">"github:user/repo"</span><span class="token punctuation">,</span>
</span><span class="code-line">  <span class="token property">"repository"</span><span class="token operator">:</span> <span class="token string">"gitlab:user/repo"</span><span class="token punctuation">,</span>
</span><span class="code-line">  <span class="token property">"repository"</span><span class="token operator">:</span> <span class="token string">"bitbucket:user/repo"</span><span class="token punctuation">,</span>
</span><span class="code-line">  <span class="token property">"repository"</span><span class="token operator">:</span> <span class="token string">"gist:a1b2c3d4e5f"</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>包的实际代码所在的位置。</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="bugs"><a aria-hidden="true" tabindex="-1" href="#bugs"><span class="icon icon-link"></span></a><code>bugs</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"bugs"</span><span class="token operator">:</span> <span class="token string">"https://github.com/user/repo/issues"</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>问题反馈系统的 URL，或者是 email 地址之类的链接。用户通过该途径向你反馈问题。</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="项目维护类字段"><a aria-hidden="true" tabindex="-1" href="#项目维护类字段"><span class="icon icon-link"></span></a>项目维护类字段</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="author"><a aria-hidden="true" tabindex="-1" href="#author"><span class="icon icon-link"></span></a><code>author</code></h3><div class="wrap-body">
<p>项目的维护者。</p>
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"author"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Your Name"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"email"</span><span class="token operator">:</span> <span class="token string">"you@xxx.com"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"url"</span><span class="token operator">:</span> <span class="token string">"http://your-x.com"</span>
</span><span class="code-line">  <span class="token punctuation">}</span><span class="token punctuation">,</span>
</span><span class="code-line">  <span class="token property">"author"</span><span class="token operator">:</span> <span class="token string">"Your Name &#x3C;you@xxx.com> (http://your-x.com)"</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>作者信息，一个人。</p>
</div></div></div><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="contributors"><a aria-hidden="true" tabindex="-1" href="#contributors"><span class="icon icon-link"></span></a><code>contributors</code></h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"contributors"</span><span class="token operator">:</span> <span class="token punctuation">[</span>
</span><span class="code-line">    <span class="token punctuation">{</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Your Friend"</span><span class="token punctuation">,</span> <span class="token property">"email"</span><span class="token operator">:</span> <span class="token string">"friend@xxx.com"</span><span class="token punctuation">,</span> <span class="token property">"url"</span><span class="token operator">:</span> <span class="token string">"http://friends-xx.com"</span> <span class="token punctuation">}</span>
</span><span class="code-line">    <span class="token punctuation">{</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Other Friend"</span><span class="token punctuation">,</span> <span class="token property">"email"</span><span class="token operator">:</span> <span class="token string">"other@xxx.com"</span><span class="token punctuation">,</span> <span class="token property">"url"</span><span class="token operator">:</span> <span class="token string">"http://other-xx.com"</span> <span class="token punctuation">}</span>
</span><span class="code-line">  <span class="token punctuation">]</span><span class="token punctuation">,</span>
</span><span class="code-line">  <span class="token property">"contributors"</span><span class="token operator">:</span> <span class="token punctuation">[</span>
</span><span class="code-line">    <span class="token string">"Your Friend &#x3C;friend@xxx.com> (http://friends-xx.com)"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token string">"Other Friend &#x3C;other@xxx.com> (http://other-xx.com)"</span>
</span><span class="code-line">  <span class="token punctuation">]</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>贡献者信息，可能很多人。</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="文件类信息"><a aria-hidden="true" tabindex="-1" href="#文件类信息"><span class="icon icon-link"></span></a>文件类信息</h2><div class="wrap-body">
<p>指定包含在项目中的文件，以及项目的入口文件。</p>
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="files"><a aria-hidden="true" tabindex="-1" href="#files"><span class="icon icon-link"></span></a><code>files</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"files"</span><span class="token operator">:</span> <span class="token punctuation">[</span>
</span><span class="code-line">    <span class="token string">"filename.js"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token string">"directory/"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token string">"glob/*.{js,json}"</span>
</span><span class="code-line">  <span class="token punctuation">]</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>项目包含的文件，可以是单独的文件、整个文件夹，或者通配符匹配到的文件。</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="main"><a aria-hidden="true" tabindex="-1" href="#main"><span class="icon icon-link"></span></a><code>main</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"main"</span><span class="token operator">:</span> <span class="token string">"filename.js"</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>项目的入口文件。</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="man"><a aria-hidden="true" tabindex="-1" href="#man"><span class="icon icon-link"></span></a><code>man</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"man"</span><span class="token operator">:</span> <span class="token string">"./man/doc.1"</span><span class="token punctuation">,</span>
</span><span class="code-line">  <span class="token property">"man"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">"./man/doc.1"</span><span class="token punctuation">,</span> <span class="token string">"./man/doc.2"</span><span class="token punctuation">]</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>项目的入口文件。</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="directories"><a aria-hidden="true" tabindex="-1" href="#directories"><span class="icon icon-link"></span></a><code>directories</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"directories"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"lib"</span><span class="token operator">:</span> <span class="token string">"path/to/lib/"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"bin"</span><span class="token operator">:</span> <span class="token string">"path/to/bin/"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"man"</span><span class="token operator">:</span> <span class="token string">"path/to/man/"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"doc"</span><span class="token operator">:</span> <span class="token string">"path/to/doc/"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"example"</span><span class="token operator">:</span> <span class="token string">"path/to/example/"</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>当你的包安装时，你可以指定确切的位置来放二进制文件、man pages、文档、例子等。</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="bin"><a aria-hidden="true" tabindex="-1" href="#bin"><span class="icon icon-link"></span></a><code>bin</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"bin"</span><span class="token operator">:</span> <span class="token string">"bin.js"</span><span class="token punctuation">,</span>
</span><span class="code-line">  <span class="token property">"bin"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"命令名称"</span><span class="token operator">:</span> <span class="token string">"bin/命令路径/命令名称.js"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"other-command"</span><span class="token operator">:</span> <span class="token string">"bin/other-command"</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>随着项目一起被安装的可执行文件。</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="types"><a aria-hidden="true" tabindex="-1" href="#types"><span class="icon icon-link"></span></a><code>types</code></h3><div class="wrap-body">
<p>这是一个只在 <a href="https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html">TypeScript</a> 中生效的字段，如果您的包有一个 <code>main.js</code> 文件，您还需要在  <code>package.json</code> 文件中指明主声明文件。 将 <code>types</code> 属性设置为指向 <code>bundled</code> 的声明文件。 例如：</p>
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"types"</span><span class="token operator">:</span> <span class="token string">"./lib/main.d.ts"</span><span class="token punctuation">,</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>如果您的主声明文件名为 <code>index.d.ts</code> 并且位于包的根目录（<code>index.js</code>旁边），则不需要标记 <code>types</code> 属性，建议这样做。</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="打包包字段"><a aria-hidden="true" tabindex="-1" href="#打包包字段"><span class="icon icon-link"></span></a>打包包字段</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist col-span-2 row-span-2"><div class="wrap-header h3wrap"><h3 id="esnext"><a aria-hidden="true" tabindex="-1" href="#esnext"><span class="icon icon-link"></span></a><code>esnext</code></h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2 row-span-2-->
<p>完整的<a href="http://2ality.com/2017/04/transpiling-dependencies-babel.html">提案在这里</a>。 简短说明：</p>
<ul>
<li><code>esnext</code>：ES模块中使用阶段4功能（或更旧版本）的源代码，未编译。</li>
<li><code>main</code>：指向一个CommonJS模块（或UMD模块），其 <code>JavaScript</code> 与 <code>Node.js</code> 当前可以处理的一样现代。</li>
<li>大多数 <code>module</code> 用例应该可以通过 <code>esnext</code> 处理。</li>
<li><code>browser</code> 可以通过 <code>esnext</code> 的扩展版本来处理</li>
</ul>
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"main"</span><span class="token operator">:</span> <span class="token string">"main.js"</span><span class="token punctuation">,</span>
</span><span class="code-line">  <span class="token property">"esnext"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"main"</span><span class="token operator">:</span> <span class="token string">"main-esnext.js"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"browser"</span><span class="token operator">:</span> <span class="token string">"browser-specific-main-esnext.js"</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>另请参阅：<a href="http://2ality.com/2017/06/pkg-esnext.html">通过 npm 交付未编译的源代码</a></p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="module"><a aria-hidden="true" tabindex="-1" href="#module"><span class="icon icon-link"></span></a><code>module</code></h3><div class="wrap-body">
<p><code>pkg.module</code> 将指向具有 <code>ES2015</code> 模块语法的模块，但仅指向目标环境支持的语法功能。 完整的描述<a href="https://github.com/rollup/rollup/wiki/pkg.module">在这里</a>。</p>
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"module"</span><span class="token operator">:</span> <span class="token string">"dist/my-package.esm.js"</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>支持：<a href="https://github.com/rollup/rollup-plugin-node-resolve">rollup</a>, <a href="https://webpack.js.org/configuration/resolve/#resolve-mainfields">webpack</a></p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="browser"><a aria-hidden="true" tabindex="-1" href="#browser"><span class="icon icon-link"></span></a><code>browser</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token property">"browser"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"module-a"</span><span class="token operator">:</span> <span class="token string">"./shims/module-a.js"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"./server/only.js"</span><span class="token operator">:</span> <span class="token string">"./shims/client-only.js"</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>字段由模块作者提供，作为 <code>JavaScript</code> 包或组件工具的提示，用于打包模块以供客户端使用。 提案就<a href="https://github.com/defunctzombie/package-browser-field-spec">在这里</a>。</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="exports-导出"><a aria-hidden="true" tabindex="-1" href="#exports-导出"><span class="icon icon-link"></span></a>exports 导出</h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"mod"</span><span class="token punctuation">,</span>
</span><span class="code-line">  <span class="token property">"exports"</span><span class="token operator">:</span><span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"."</span><span class="token operator">:</span> <span class="token string">"./lib/index.js"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"./lib/*"</span><span class="token operator">:</span> <span class="token string">"./lib/*.js"</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>使用最新的 <code>exports</code> 字段导出，可规避 <code>main</code> 字段局限性 <a href="https://nodejs.org/api/packages.html">具体参考</a></p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="exports-导出子路径中的模块"><a aria-hidden="true" tabindex="-1" href="#exports-导出子路径中的模块"><span class="icon icon-link"></span></a>exports 导出子路径中的模块</h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"mod"</span><span class="token punctuation">,</span>
</span><span class="code-line">  <span class="token property">"exports"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"."</span><span class="token operator">:</span> <span class="token string">"./index.js"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"./sub"</span><span class="token operator">:</span> <span class="token string">"./src/sub.js"</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>导入</p>
<pre class="language-js"><code class="language-js code-highlight"><span class="code-line"><span class="token keyword module">import</span> <span class="token imports">sub</span> <span class="token keyword module">from</span> <span class="token string">"mod/sub"</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="exports-简写--唯一的导出"><a aria-hidden="true" tabindex="-1" href="#exports-简写--唯一的导出"><span class="icon icon-link"></span></a>exports 简写 (<code>.</code> 唯一的导出)</h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"exports"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"."</span><span class="token operator">:</span> <span class="token string">"./dist/index.js"</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>简写</p>
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"exports"</span><span class="token operator">:</span> <span class="token string">"./dist/index.js"</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist col-span-2 row-span-2"><div class="wrap-header h3wrap"><h3 id="条件导出exports"><a aria-hidden="true" tabindex="-1" href="#条件导出exports"><span class="icon icon-link"></span></a>条件导出(exports)</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2 row-span-2-->

























<table><thead><tr><th align="left">:-</th><th>-</th></tr></thead><tbody><tr><td align="left"><code>export</code></td><td>通过 <code>import</code> 或 <code>import()</code> 或 <code>es</code> 模块加载的任何顶层导入或解析操作加载时，匹配。</td></tr><tr><td align="left"><code>require</code></td><td>当包通过 <code>require()</code> 加载时匹配。预期的格式包括 CommonJS、JSON 和本地插件。</td></tr><tr><td align="left"><code>node</code></td><td>匹配任何 <code>Node.js</code> 环境。可以是 <code>cjs</code> 或 <code>es</code> 模块文件。必须在 <code>import</code> 或 <code>require</code> 之后。</td></tr><tr><td align="left"><code>default</code></td><td>默认的降级条件。可以是一个 <code>cjs</code> 或 <code>es</code> 模块文件。这个条件应该总是排在最后。</td></tr></tbody></table>
<pre class="language-js"><code class="language-js code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token string-property property">"exports"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token string-property property">"."</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">      <span class="token string-property property">"import"</span><span class="token operator">:</span><span class="token string">"./dist/index.mjs"</span><span class="token punctuation">,</span>
</span><span class="code-line">      <span class="token string-property property">"require"</span><span class="token operator">:</span><span class="token string">"./dist/index.cjs"</span><span class="token punctuation">,</span>  <span class="token comment">// 当包通过 `require()` 加载时匹配</span>
</span><span class="code-line">      <span class="token string-property property">"node"</span><span class="token operator">:</span> <span class="token string">"./dist/ployfill.js"</span><span class="token punctuation">,</span>  <span class="token comment">// 匹配任何 `Node.js` 环境</span>
</span><span class="code-line">      <span class="token string-property property">"default"</span><span class="token operator">:</span> <span class="token string">"./dist/default.js"</span> <span class="token comment">// 默认的降级条件</span>
</span><span class="code-line">    <span class="token punctuation">}</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p><red>注意：</red>由于 <code>require</code> 和 <code>import</code> 互斥，所以 <code>require</code> 不能加载 <code>es</code> 的模块，<code>export</code> 不能加载 <code>cjs</code> 模块</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="main-vs-exports"><a aria-hidden="true" tabindex="-1" href="#main-vs-exports"><span class="icon icon-link"></span></a><code>main</code> Vs <code>exports</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"main"</span><span class="token operator">:</span> <span class="token string">"./index.js"</span><span class="token punctuation">,</span>
</span><span class="code-line">  <span class="token property">"exports"</span><span class="token operator">:</span> <span class="token string">"./index.js"</span>
</span><span class="code-line"><span class="token punctuation">}</span> 
</span></code></pre>
<p>如果同时出现 <red><del><code>main</code></del></red> 和 <code>exports</code> 字段，只会读取 <code>exports</code> 字段</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="任务类字段"><a aria-hidden="true" tabindex="-1" href="#任务类字段"><span class="icon icon-link"></span></a>任务类字段</h2><div class="wrap-body">
<p>包里还可以包含一些可执行脚本或者其他配置信息。</p>
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="scripts"><a aria-hidden="true" tabindex="-1" href="#scripts"><span class="icon icon-link"></span></a><code>scripts</code></h3><div class="wrap-body">
<p>脚本是定义自动化开发相关任务的好方法，比如使用一些简单的构建过程或开发工具。 在 <code>scripts</code> 字段里定义的脚本，可以通过 <code>yarn run &#x3C;script></code> 命令来执行。 例如，下面 <code>build-project</code> 脚本可以通过 <code>yarn run build-project</code> 调用，并执行 <code>node build-project.js</code>。</p>
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"scripts"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"build-project"</span><span class="token operator">:</span> <span class="token string">"node build-project.js"</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>有一些特殊的脚本名称。 如果定义了 <code>preinstall</code> 脚本，它会在包安装前被调用。 出于兼容性考虑，<code>install</code>、<code>postinstall</code> 和 <code>prepublish</code> 脚本会在包完成安装后被调用。</p>
<hr>
<p><code>start</code> 脚本的默认值为 <code>node server.js</code>。</p>
<hr>
<p>参考文档：<a href="https://docs.npmjs.com/files/package.json#default-values">npm docs</a></p>
</div></div></div><div class="wrap h3body-not-exist col-span-2 row-span-2"><div class="wrap-header h3wrap"><h3 id="特定的-scripts"><a aria-hidden="true" tabindex="-1" href="#特定的-scripts"><span class="icon icon-link"></span></a>特定的 <code>scripts</code></h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2 row-span-2-->
<p>对于以下脚本，<code>npm</code> 支持 <code>package.json</code> 文件的 <code>scripts</code> 默认命令字段：</p>
<ul>
<li><code>prepublish</code>: 在打包并发布包之前运行，以及在没有任何参数的本地 <code>npm</code> 安装之前运行</li>
<li><code>prepare</code>: 在打包和发布包之前运行，在没有任何参数的本地 <code>npm install</code> 上运行，以及安装 git 依赖项时。 这是在 <code>preublish</code> 之后运行，但是在 <code>preublishOnly</code> 之前运行</li>
<li><code>prepublishOnly</code>: 在包准备和打包之前运行，仅限于npm发布</li>
<li><code>prepack</code>: 在打包 <code>tarball</code> 之前运行（在 <code>npm pack</code>，<code>npm publish</code>，以及安装 git 依赖项时）</li>
<li><code>postpack</code>: 在生成 <code>tarball</code> 之后运行并移动到其最终目标</li>
<li><code>publish</code>, <code>postpublish</code>: 在包发布后运行</li>
<li><code>preinstall</code>: 在安装软件包之前运行</li>
<li><code>install</code>, <code>postinstall</code>: 安装包后运行</li>
<li><code>preuninstall</code>, <code>uninstall</code>: 在卸载软件包之前运行</li>
<li><code>postuninstall</code>: 在卸载软件包之后运行</li>
<li><code>preversion</code>: 在改变包版本之前运行</li>
<li><code>version</code>: 改变包版本后运行，但提交之前</li>
<li><code>postversion</code>: 改变包版本后运行，然后提交</li>
<li><code>pretest</code>, <code>test</code>, <code>posttest</code>: 由 <code>npm test</code> 命令运行</li>
<li><code>prestop</code>, <code>stop</code>, <code>poststop</code>: 由 <code>npm stop</code> 命令运行</li>
<li><code>prestart</code>, <code>start</code>, <code>poststart</code>: 由 <code>npm start</code> 命令运行</li>
<li><code>prerestart</code>, <code>restart</code>, <code>postrestart</code>: 由 <code>npm restart</code> 命令运行。 注意：如果没有提供重启脚本，<code>npm restart</code> 将运行 <code>stop</code> 和<code>start</code> 脚本</li>
<li><code>preshrinkwrap</code>, <code>shrinkwrap</code>, <code>postshrinkwrap</code>: 由 <code>npm shrinkwrap</code> 命令运行</li>
</ul>
<p>参考文档：<a href="https://docs.npmjs.com/misc/scripts">npm docs</a>.</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="config"><a aria-hidden="true" tabindex="-1" href="#config"><span class="icon icon-link"></span></a><code>config</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"config"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"port"</span><span class="token operator">:</span> <span class="token string">"8080"</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>配置你的脚本的选项或参数。</p>
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"scripts"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"run"</span><span class="token operator">:</span> <span class="token string">"echo $npm_package_config_port"</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>配置中的键作为环境变量公开给脚本(scripts)。</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="依赖描述类字段"><a aria-hidden="true" tabindex="-1" href="#依赖描述类字段"><span class="icon icon-link"></span></a>依赖描述类字段</h2><div class="wrap-body">
<p>你的包很可能依赖其他包。你可以在你的 <code>package.json</code> 文件里指定那些依赖。</p>
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist col-span-2 row-span-2"><div class="wrap-header h3wrap"><h3 id="dependencies"><a aria-hidden="true" tabindex="-1" href="#dependencies"><span class="icon icon-link"></span></a><code>dependencies</code></h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2 row-span-2-->
<p>这些是你的包的开发版和发布版都需要的依赖。</p>
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"dependencies"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"colors"</span><span class="token operator">:</span>   <span class="token string">"*"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"foo"</span><span class="token operator">:</span> <span class="token string">"1.0.0 - 2.9999.9999"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"bar"</span><span class="token operator">:</span> <span class="token string">">=1.0.2 &#x3C;2.1.2"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"baz"</span><span class="token operator">:</span> <span class="token string">">1.0.2 &#x3C;=2.3.4"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"boo"</span><span class="token operator">:</span> <span class="token string">"2.0.1"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"qux"</span><span class="token operator">:</span> <span class="token string">"&#x3C;1.0.0 || >=2.3.1 &#x3C;2.4.5 || >=2.5.2 &#x3C;3.0.0"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"asd"</span><span class="token operator">:</span> <span class="token string">"http://asdf.com/asdf.tar.gz"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"til"</span><span class="token operator">:</span> <span class="token string">"~1.2"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"elf"</span><span class="token operator">:</span> <span class="token string">"~1.2.3"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"two"</span><span class="token operator">:</span> <span class="token string">"2.x"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"thr"</span><span class="token operator">:</span> <span class="token string">"3.3.x"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"lat"</span><span class="token operator">:</span> <span class="token string">"latest"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"dyl"</span><span class="token operator">:</span> <span class="token string">"file:./path/to/dyl"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"pla"</span><span class="token operator">:</span> <span class="token string">"https://github.com/user/project/tarball/branch"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"stu"</span><span class="token operator">:</span> <span class="token string">"git://github.com/user/project.git#commit-ish"</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>你可以指定一个确切的版本、一个最小的版本 (比如 <code>>=</code>) 或者一个版本范围 (比如 <code>>= ... &#x3C;</code>)。 包也可以指向本地的一个目录文件夹。
参考文档：<a href="https://docs.npmjs.com/cli/v8/configuring-npm/package-json#dependencies">npm docs</a>.</p>
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="workspaces"><a aria-hidden="true" tabindex="-1" href="#workspaces"><span class="icon icon-link"></span></a>workspaces</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"my-workspaces-powered-project"</span><span class="token punctuation">,</span>
</span><span class="code-line">  <span class="token property">"workspaces"</span><span class="token operator">:</span> <span class="token punctuation">[</span>
</span><span class="code-line">    <span class="token string">"./pkg/*"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token string">"packages/a"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token string">"packages/b"</span>
</span><span class="code-line">  <span class="token punctuation">]</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>支持从单个顶级根包中管理本地文件系统中的多个包。</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">├┈┈ node_modules
</span><span class="code-line">┆  ├┈┈ a -<span class="token operator">></span> <span class="token punctuation">..</span>/packages/a
</span><span class="code-line">┆  ╰┈┈ b -<span class="token operator">></span> <span class="token punctuation">..</span>/packages/b
</span><span class="code-line">├┈┈ package-lock.json
</span><span class="code-line">├┈┈ package.json
</span><span class="code-line">╰┈┈ packages
</span><span class="code-line">   ├┈┈ a
</span><span class="code-line">   ┆   ╰┈┈ package.json
</span><span class="code-line">   ├┈┈ b
</span><span class="code-line">   ┆   ╰┈┈ package.json
</span></code></pre>
<p>参考文档：<a href="https://docs.npmjs.com/cli/v8/using-npm/workspaces">workspaces</a></p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="devdependencies"><a aria-hidden="true" tabindex="-1" href="#devdependencies"><span class="icon icon-link"></span></a><code>devDependencies</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"devDependencies"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"package-2"</span><span class="token operator">:</span> <span class="token string">"^0.4.2"</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>这些是只在你的包开发期间需要，但是生产环境不会被安装的包。</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="overrides"><a aria-hidden="true" tabindex="-1" href="#overrides"><span class="icon icon-link"></span></a><code>overrides</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"overrides"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"foo"</span><span class="token operator">:</span> <span class="token string">"1.0.0"</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>对依赖项的依赖项进行特定更改，例如用已知的安全问题替换依赖项的版本</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="peerdependencies"><a aria-hidden="true" tabindex="-1" href="#peerdependencies"><span class="icon icon-link"></span></a><code>peerDependencies</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"peerDependencies"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"package-3"</span><span class="token operator">:</span> <span class="token string">"^2.7.18"</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>平行依赖允许你说明你的包和其他包版本的兼容性。添加可选设置以消除丢失的对等依赖性警告，<a href="https://github.com/yarnpkg/yarn/pull/6671">#6671</a> 。</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="optionaldependencies"><a aria-hidden="true" tabindex="-1" href="#optionaldependencies"><span class="icon icon-link"></span></a><code>optionalDependencies</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"optionalDependencies"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"package-5"</span><span class="token operator">:</span> <span class="token string">"^1.6.1"</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>可选依赖可以用于你的包，但不是必需的。如果可选包没有找到，安装还可以继续。</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="bundleddependencies"><a aria-hidden="true" tabindex="-1" href="#bundleddependencies"><span class="icon icon-link"></span></a><code>bundledDependencies</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"bundledDependencies"</span><span class="token operator">:</span> <span class="token punctuation">[</span>
</span><span class="code-line">    <span class="token string">"package-4"</span>
</span><span class="code-line">  <span class="token punctuation">]</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>打包依赖是发布你的包时将会一起打包的一个包名数组。</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="peerdependenciesmeta"><a aria-hidden="true" tabindex="-1" href="#peerdependenciesmeta"><span class="icon icon-link"></span></a><code>peerDependenciesMeta</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"peerDependenciesMeta"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"node-sass"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">      <span class="token property">"optional"</span><span class="token operator">:</span> <span class="token boolean">true</span>
</span><span class="code-line">    <span class="token punctuation">}</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"sass"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">      <span class="token property">"optional"</span><span class="token operator">:</span> <span class="token boolean">true</span>
</span><span class="code-line">    <span class="token punctuation">}</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"fibers"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">      <span class="token property">"optional"</span><span class="token operator">:</span> <span class="token boolean">true</span>
</span><span class="code-line">    <span class="token punctuation">}</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>它允许对等依赖项标记为可选</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="系统"><a aria-hidden="true" tabindex="-1" href="#系统"><span class="icon icon-link"></span></a>系统</h2><div class="wrap-body">
<p>你可以提供和你的包关联的系统级的信息，比如操作系统兼容性之类。</p>
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist col-span-2 row-span-2"><div class="wrap-header h3wrap"><h3 id="engines"><a aria-hidden="true" tabindex="-1" href="#engines"><span class="icon icon-link"></span></a><code>engines</code></h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2 row-span-2-->
<p>指定使用你的包客户必须使用的版本，这将检查 <code>process.versions</code> 以及当前 <code>yarn</code> 版本。</p>
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"engines"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"node"</span><span class="token operator">:</span> <span class="token string">"^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"node"</span><span class="token operator">:</span> <span class="token string">">=4.4.7 &#x3C;7.0.0"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"zlib"</span><span class="token operator">:</span> <span class="token string">"^1.2.8"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"yarn"</span><span class="token operator">:</span> <span class="token string">"^0.14.0"</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>此检查遵守正常的 <a href="http://semver.org/lang/zh-CN/">semver</a> 规则，但有一个例外。 它允许预发布版本匹配未明确指定预发布的 <a href="http://semver.org/lang/zh-CN/">semver</a>。 例如，<code>1.4.0-rc.0</code> 匹配 <code>>=1.3.0</code>，但它与典型的 <code>semver</code> 检查不匹配。</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="os"><a aria-hidden="true" tabindex="-1" href="#os"><span class="icon icon-link"></span></a><code>os</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"os"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">"darwin"</span><span class="token punctuation">,</span> <span class="token string">"linux"</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
</span><span class="code-line">  <span class="token property">"os"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">"!win32"</span><span class="token punctuation">]</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>此选项指定你的包的操作系统兼容性，它会检查 <code>process.platform</code>。</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="cpu"><a aria-hidden="true" tabindex="-1" href="#cpu"><span class="icon icon-link"></span></a><code>cpu</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"cpu"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">"x64"</span><span class="token punctuation">,</span> <span class="token string">"ia32"</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
</span><span class="code-line">  <span class="token property">"cpu"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">"!arm"</span><span class="token punctuation">,</span> <span class="token string">"!mips"</span><span class="token punctuation">]</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>使用这个选项指定你的包将只能在某些 CPU 体系架构上运行，这会检查 <code>process.arch</code>。</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="发布"><a aria-hidden="true" tabindex="-1" href="#发布"><span class="icon icon-link"></span></a>发布</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="private"><a aria-hidden="true" tabindex="-1" href="#private"><span class="icon icon-link"></span></a><code>private</code></h3><div class="wrap-body">
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"private"</span><span class="token operator">:</span> <span class="token boolean">true</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>如果你不想你的包发布到包管理器(npm 或者 私有包管理)，设置为 <code>true</code>。</p>
</div></div></div><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="publishconfig"><a aria-hidden="true" tabindex="-1" href="#publishconfig"><span class="icon icon-link"></span></a><code>publishConfig</code></h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->
<p>这些配置值将在你的包发布时使用。比如，你可以给包打标签。</p>
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"publishConfig"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"registry"</span><span class="token operator">:</span> <span class="token string">"https://registry.npm.taobao.org"</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>这是一组将在发布时使用的配置值。 如果要设置标记，注册表或访问权限，则特别方便，以便确保给定的包未标记为 <code>latest</code>，发布到全局公共 <code>registry</code> 或默认情况下，作用域模块(@scoped)是私有的。</p>
<p>可以覆盖任何配置值，但只有 <code>tag</code>，<code>registry</code> 和 <code>access</code> 可能对于发布而言很重要，<a href="https://docs.npmjs.com/misc/config#config-settings">npm-config</a>。</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="yarn"><a aria-hidden="true" tabindex="-1" href="#yarn"><span class="icon icon-link"></span></a>Yarn</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="flat"><a aria-hidden="true" tabindex="-1" href="#flat"><span class="icon icon-link"></span></a><code>flat</code></h3><div class="wrap-body">
<!-- markdownlint-disable MD042 -->
<p>如果你的包只允许给定依赖的一个版本，你想强制和命令行上 <a href="#">yarn install --flat</a> 相同的行为，把这个值设为 <code>true</code>。</p>
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"flat"</span><span class="token operator">:</span> <span class="token boolean">true</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>请注意，如果你的 <code>package.json</code> 包含 <code>"flat": true</code> 并且其它包依赖你的包 (比如你在构建一个库，而不是应用)， 其它那些包也需要在它们的 <code>package.json</code> 加上 <code>"flat": true</code>，或者在命令行上用 <code>yarn install --flat</code> 安装。</p>
</div></div></div><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="resolutions"><a aria-hidden="true" tabindex="-1" href="#resolutions"><span class="icon icon-link"></span></a><code>resolutions</code></h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->
<pre class="language-json"><code class="language-json code-highlight"><span class="code-line"><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token property">"resolutions"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token property">"transitive-package-1"</span><span class="token operator">:</span> <span class="token string">"0.0.29"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"transitive-package-2"</span><span class="token operator">:</span> <span class="token string">"file:./local-forks/transitive-package-2"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token property">"dependencies-package-1/transitive-package-3"</span><span class="token operator">:</span> <span class="token string">"^2.1.1"</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>允许您覆盖特定嵌套依赖项的版本。 有关完整规范，请参见<a href="https://github.com/yarnpkg/rfcs/blob/master/implemented/0000-selective-versions-resolutions.md">选择性版本解析 RFC</a>。</p>
<p>注意，<code>yarn install --flat</code> 命令将会自动在 <code>package.json</code> 文件里加入 <code>resolutions</code> 字段。</p>
</div></div></div></div></div><div class="wrap h2body-not-exist"><div class="wrap-header h2wrap"><h2 id="另见"><a aria-hidden="true" tabindex="-1" href="#另见"><span class="icon icon-link"></span></a>另见</h2><div class="wrap-body">
<ul>
<li><a href="https://jaywcjlove.github.io/package.json">PACKAGE.JSON 中文说明</a> <em>(github.io)</em></li>
<li><a href="https://docs.npmjs.com/files/package.json">npm 文档</a> <em>(npmjs.com)</em></li>
<li><a href="https://classic.yarnpkg.com/en/docs/package-json">yarnpkg 文档</a> <em>(yarnpkg.com)</em></li>
<li><a href="https://nodejs.org/api/packages.html">packages 文档</a> <em>(nodejs.org)</em></li>
<li><a href="./npm.html">npm 备忘清单(速查表)</a> <em>(jaywcjlove.github.io)</em></li>
</ul>
</div></div><div class="h2wrap-body"></div></div></div></div><footer class="footer-wrap"><footer class="max-container">© 2022 Kenny Wang.</footer></footer><script src="../data.js" defer></script><script src="../js/fuse.min.js" defer></script><script src="../js/main.js" defer></script><div id="mysearch"><div class="mysearch-box"><div class="mysearch-input"><div><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 18 18">
  <path fill="currentColor" d="M17.71,16.29 L14.31,12.9 C15.4069846,11.5024547 16.0022094,9.77665502 16,8 C16,3.581722 12.418278,0 8,0 C3.581722,0 0,3.581722 0,8 C0,12.418278 3.581722,16 8,16 C9.77665502,16.0022094 11.5024547,15.4069846 12.9,14.31 L16.29,17.71 C16.4777666,17.8993127 16.7333625,18.0057983 17,18.0057983 C17.2666375,18.0057983 17.5222334,17.8993127 17.71,17.71 C17.8993127,17.5222334 18.0057983,17.2666375 18.0057983,17 C18.0057983,16.7333625 17.8993127,16.4777666 17.71,16.29 Z M2,8 C2,4.6862915 4.6862915,2 8,2 C11.3137085,2 14,4.6862915 14,8 C14,11.3137085 11.3137085,14 8,14 C4.6862915,14 2,11.3137085 2,8 Z"></path>
</svg><input id="mysearch-input" type="search" placeholder="搜索" autocomplete="off"><div class="mysearch-clear"></div></div><button id="mysearch-close" type="button">搜索</button></div><div class="mysearch-result"><div id="mysearch-menu"></div><div id="mysearch-content"></div></div></div></div></body>
</html>
